package com.qf.day6;

import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

/**
 * @date 2022/4/2
 * @desc
 *
 * 事件源
 * 事件
 * 监听器
 */
public class Listener1Demo {

    public static void main(String[] args) {

        Frame frame = new Frame();

        frame.setSize(400,400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        // frame  事件源
        //事件   WindowEvent e
        //监听器 WindowListener
        frame.addWindowListener(new WindowListener() {
            @Override
            public void windowOpened(WindowEvent e) {

            }

            @Override
            public void windowClosing(WindowEvent e) {
                System.out.println("你正在关闭窗口");

                Frame source = (Frame) e.getSource();

                source.dispose();
            }

            @Override
            public void windowClosed(WindowEvent e) {

            }

            @Override
            public void windowIconified(WindowEvent e) {

            }

            @Override
            public void windowDeiconified(WindowEvent e) {

            }

            @Override
            public void windowActivated(WindowEvent e) {

            }

            @Override
            public void windowDeactivated(WindowEvent e) {

            }
        });


    }

}
